<script type="text/javascript">
  
    function printPage(id) {
        //alert('successfully');
        var html="<fieldset>";
        html+= document.getElementById(id).innerHTML;
        html+="</fieldset>";

        var printWin = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status =0');
        printWin.document.write(html);
        printWin.document.close();
        printWin.focus();
        printWin.print();
        printWin.close();

        var html="<html>";
        html+="<head>";
         html+="<style type='text/css'>.mytable{border:1px solid #ccc;}.mytable tr{background-color:#008000;color:#FFF;}</style>";
        html+="<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/bootstrap.css' media='print' />";
        html+="<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/bootstrap-responsive.css' media='print' />";
        html+="<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/style.css' media='print' />";
        html+="<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/demo_table_jui.css' media='print' />";
        html+="</head>";
        html+= document.getElementById(id).innerHTML;
        html+="</html>";
  
    }
</script>
        
    <?php

echo '<fieldset id="year" style="border:1px solid #239DA9 ;margin: 0 auto;width:96%;height: auto; padding:20px;border-radius:5px;">';
echo '<div style="float:right; margin-right: 15px;">';
echo anchor('report/show_report', img('images/cancel.png'), array('title' => 'Back'));
echo '</div>';
?><div style=" height: 50px;  margin:10px;"><img src="<?php echo base_url(); ?>/images/login_logo.png" align="center"   alt="Print semester report" />
<?php
echo '<h1 style="color: #239DA9;
    font-family: verdana;
    font-size: 20px;
    font-style: italic;
    font-weight: bold;
    text-shadow: 1px 1px 1px #8483E1;
    margin-top:-50px;
    text-decoration: underline;
    text-align: center;">Leaving Report For '. date("F") .' </h1></div>';
echo '<br/><div style="float:right;color:#239DA9;width:40%;text-align:right; margin-right: 15px; padding-bottom: 15px;">View Semester Report For  Month&nbsp;:' . '<b style="color:red;"> ' . date("F/Y") . '</b><br/>';
?>

To print this report, Click here<a href="#">
    <img src="<?php echo base_url(); ?>/images/print.png" align="center" onclick="return printPage('year');" id="image"  alt="Print semester report" title="Print semester report"/>
</a></div>
        <table  cellpadding="0" cellspacing="0" border="1" style="border: 1px solid #CCC; text-align: center; width: 1100px; margin: auto;">
            <thead>
                <tr style="color: #239DA9;" >
                    <th colspan="4" style="height: 40px; ">Detail</th>
                    <th>Type of Leave</th>
                    <th>Total</th>
                </tr>
              <tr style="color: #239DA9;" >
                    <th>Staff_Name</th>
                    <th>Gender</th>
                    <th>Department</th>
                    <!--<th>Group</th>-->
                    <th>
                        <table style="width:800px;"  cellpadding="0" cellspacing="0">
                            <tr style="color: #239DA9;" >
                                <th style="height: 40px;">Start_date</th>
                                <th>End_date</th>
                                <th>Annual</th>
                                <th>Catch_Up</th>
                                <th>Impossed</th>
                                <th>Personal</th>
                                <th>Special</th>
                        </tr>
                            
                        </table>
                    </th>
                    <th>Sub_Total</th>
              </tr>
            </thead>
            <tbody>
                <?php
                foreach ($staff->result_array() as $rows) {
                    $staff_id = $rows['staff_id'];
                    $this->db->select('*');
                    $this->db->from('pnc_record');
                    $this->db->where('staff_id', $staff_id);
                    $this->db->where('month( start_date ) = month( CURDATE( ) ) and month( end_date ) = month( CURDATE( ) )');
                    $month = $this->db->get();
                    
                    $gender = $rows['emp_gender'];
                    $name = $rows['username'];
                    $department = $rows['dept_name'];
//                    $group = $rows['grp_name'];
                    ?>                      
                    <tr>
                        <td> <?php echo $name; ?></td>
                        <td> <?php echo $gender; ?></td>
                        <td> <?php echo $department; ?></td>
                        <!--<td> <?php echo $group; ?></td>-->
                        <td>
           <?php
                  $annul=0;
            $catch_up=0;
           
            foreach ($month->result_array() as $subQuery){
                          ?>
                            <table cellpadding="0" cellspacing="0"  style="text-align: center; width:800px;">
                              <tr>
                                         <td style="width: 129px; height: 35px;"><?php echo $subQuery['start_date'];?></td>
                                         <td style="width: 115px;"><?php echo $subQuery['end_date'];?></td>
                                         <td style="width: 85px;"><?php
                                                if ($subQuery['lea_id'] == 1) {
                                                    echo $subQuery['duration']; 
                                                } else {
                                                    echo ('&nbsp');
                                                }
                                            ?>
                                         </td>
                                         <td style="width: 120px;">
                                                <?php
                                                if ($subQuery['lea_id'] == 2) {
                                                    echo $subQuery['duration']; 
                                                } else {
                                                    echo ('&nbsp'); 
                                                }
                                            ?>
                                         </td>
                                         <td style="width: 119px;">
                                                <?php
                                                if ($subQuery['stl_id'] ==1) {
                                                    echo $subQuery['duration'];
                                                } else { 
                                                    echo ('&nbsp;');
                                                }
                                                ?>
                                         </td>
                                          <td style="width: 107px;">
                                                <?php
                                                if ($subQuery['stl_id'] ==2) {
                                                    echo $subQuery['duration']; 
                                                } else {
                                                    echo ('&nbsp;');
                                                }
                                                ?>
                                         </td>
                                         <td style="width: 89px;">
                                                <?php
                                                if ($subQuery['stl_id'] ==3) {
                                                    echo $subQuery['duration']; 
                                                } else {
                                                    echo ('&nbsp;');
                                                }
                                                ?>
                                         </td>
                                          
                                    </tr>
                                    
                                 
                          </table>
                                      <?php
                     
            }
                    ?>


                        </td>
                        <td> <?php
            $annul=0;
            $catch_up=0;
                       foreach ($month->result_array() as $subQuery){
                        $type_id=$subQuery['lea_id'];
			$id=$subQuery ['duration'];
			
			if($type_id==1){
				$annul=$id+$annul;
			}else if($type_id==2){
				$catch_up=$id+$catch_up;
				}
			$totals=$annul+$catch_up;
            }echo '<b style="color:red;">'.$totals.'</b>';
		?></td>
                    </tr>

                    <?php
                }
                ?>
            </tbody> 
        </table>
        </br>
    </fieldset>
